package com.ruoyi.api.zero;

import com.alibaba.fastjson.JSON;
import com.ruoyi.hr.accumulationFund.domain.HrAccumulationFund;
import com.ruoyi.hr.accumulationFund.service.IHrAccumulationFundService;
import com.ruoyi.hr.socialSecurity.domain.HrSocialSecurity;
import com.ruoyi.hr.socialSecurity.service.IHrSocialSecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;

@RequestMapping("/api/zeroAccumulationFund")
@RestController
public class ZeroAccumulationFundController {
  @Autowired
  private IHrAccumulationFundService accumulationFundService;
  @PostMapping("/accumulationFundJsonImport")
  public  void accumulationFundJsonImport(){
    BufferedReader bufferedReader=null;
    ClassPathResource fileSystemResource=new ClassPathResource("hr_accumulation_fund.json");
    try {
      InputStreamReader isr = new InputStreamReader(fileSystemResource.getInputStream());
      bufferedReader=new BufferedReader(isr);
      String line=null;
      StringBuilder sb=new StringBuilder();
      while ((line=bufferedReader.readLine())!=null){

        sb.append(line);
      }
      String s = sb.toString();
      List<HrAccumulationFund> list = JSON.parseArray(s,HrAccumulationFund.class);
      System.out.println(list.size());
      for(HrAccumulationFund accumulationFund:list){
        accumulationFundService.insertHrAccumulationFund(accumulationFund);
      }
    }catch (Exception e){
      e.printStackTrace();
    }finally {
      try{
        bufferedReader.close();
      }catch (Exception e){}
    }
  }
}
